import * as actionType from './actionTypes'
import axios from 'axios'
import {fromJS} from 'immutable'

const changeList = (data) => ({
    type: actionType.CHANGE_LIST,
    data: fromJS(data),
    totalPage: Math.ceil(data.length / 10)
})

export const searchFocus = () => ({
    type: actionType.SEARCH_FOCUS
})
export const searchBlur = () => ({
    type: actionType.SEARCH_BLUR
})

export const mouseEnter = () => ({
    type: actionType.MOUSE_ENTER
})

export const mouseLeave = () => ({
    type: actionType.MOUSE_LEAVE
})

export const changePage = (page) => ({
    type: actionType.CHANGE_PAGE,
    page
})

export const getList = () => {
    return (dispatch) => {
        axios.get('https://www.easy-mock.com/mock/5aeafcbb671cac5c2b7aa069/api/headerList').then(res => {
            const data = res.data
            dispatch(changeList(data.data))
        }).catch(err => {
            console.log(err)
        })
    }
}